import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.tree.*;
import javax.swing.border.*;
import java.rmi.*;

public class Vote2 extends JInternalFrame implements ClientInterface
{
	public JPanel pan = new JPanel();
	public String rabio = "";
	public Vote2()
	{
		super("Slection Vote Client",false,true,false,false);
		this.setBounds(60,30,600,450);
		setVisible(true);
		
		Container c = getContentPane();
		c.setLayout(null);
		
		lab26.setBounds(50,20,200,20);	
		lab26.setFont(new Font("Verdana",Font.PLAIN,14));
		c.add(lab26);
		taf11.setBounds(50,45,180,20);
		c.add(taf11);
		bt8.setBounds(280,38,90,35);
		c.add(bt8);
		pan.setLayout(null);
		pan.setBorder(new LineBorder(Color.red,2));
		pan.setBackground(Color.gray);
		pan.setBounds(50,80,490,310);
		c.add(pan);
		lab28.setBounds(50,10,150,20);
		lab28.setFont(new Font("Verdana",Font.PLAIN,14));
		pan.add(lab28);
		jsp7.setBounds(50,35,390,60);
		jsp7.setBorder(new LineBorder(Color.white,2));
		txa7.setFont(new Font("Verdana",Font.PLAIN,14));
		pan.add(jsp7);
		
		butt1.setBounds(50,105,40,25);
		fielda.setBounds(90,105,350,25);
		fielda.setBorder(new LineBorder(Color.white,1));
		butt1.setBackground(Color.gray);
		butt1.setForeground(Color.white);
		butt1.setFont(new Font("Verdana",Font.BOLD,16));
		butt2.setBounds(50,135,40,25);
		butt2.setBackground(Color.gray);
		butt2.setForeground(Color.white);
		butt2.setFont(new Font("Verdana",Font.BOLD,16));
		fieldb.setBounds(90,135,350,25);
		fieldb.setBorder(new LineBorder(Color.white,1));
		butt3.setBounds(50,165,40,25);
		butt3.setBackground(Color.gray);
		butt3.setForeground(Color.white);
		butt3.setFont(new Font("Verdana",Font.BOLD,16));
		fieldc.setBounds(90,165,350,25);
		fieldc.setBorder(new LineBorder(Color.white,1));
		butt4.setBounds(50,195,40,25);
		butt4.setBackground(Color.gray);
		butt4.setForeground(Color.white);
		butt4.setFont(new Font("Verdana",Font.BOLD,16));
		fieldd.setBounds(90,195,350,25);
		fieldd.setBorder(new LineBorder(Color.white,1));
		btall.add(butt1);
		btall.add(butt2);
		btall.add(butt3);
		btall.add(butt4);
		
		pan.add(butt1);
		pan.add(fielda);
		pan.add(butt2);
		pan.add(fieldb);
		pan.add(butt3);
		pan.add(fieldc);
		pan.add(butt4);
		pan.add(fieldd);
		
		bt13.setBounds(330,230,110,28);
		bt13.setFont(new Font("Verdana",Font.PLAIN,13));
		bt13.setBorder(new LineBorder(Color.white,1));
		pan.add(bt13);
		
		pan.setVisible(false);
		bt8.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		if(taf11.getText().equals(""))
        		{
        			JOptionPane.showMessageDialog(null,"Please Enter your Voter_ID","ERROR",JOptionPane.ERROR_MESSAGE);
        		}
        		else {
        		pan.setVisible(true);
        		SetupVote();
        		}
        	}
        }
        );
		bt13.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(butt1.isSelected() == false && butt2.isSelected() == false && butt3.isSelected() == false && butt4.isSelected() == false)
				{
				JOptionPane.showMessageDialog(null,"Please cut your vote","Information",JOptionPane.ERROR_MESSAGE);
				return;
				}
				else {
				if(butt1.isSelected() == true )
				rabio = "1";
				if(butt2.isSelected() == true )
				rabio = "2";
				if(butt3.isSelected() == true )
				rabio = "3";
				if(butt4.isSelected() == true )
				rabio = "4";
				
				try {
        			
        			String ur = "rmi://"+clientconf.getText()+"/MainServer";
				MainServerInterface msin = (MainServerInterface)Naming.lookup(ur);
			
				String ra = msin.VoteSelectionAnswer(rabio);
				
			}
			catch(Exception ex)
			{
				JOptionPane.showMessageDialog(null,"Internal IIOP Error....\nContact to the Administrator..","Error",JOptionPane.ERROR_MESSAGE);
			}
			}
			}
			
		}
		);
		
		try
		{
			UIManager.setLookAndFeel(looks[1].getClassName());
			SwingUtilities.updateComponentTreeUI(this);
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
		
		
	}
	protected void SetupVote()
		{
			try {
        			
        		String ur = "rmi://"+clientconf.getText()+"/MainServer";
			MainServerInterface msin = (MainServerInterface)Naming.lookup(ur);
			
			txa7.setText(msin.VoteSelectionQuestion(taf11.getText()));
			fielda.setText(msin.VoteSelectionSect1(""));
			fieldb.setText(msin.VoteSelectionSect2(""));
			fieldc.setText(msin.VoteSelectionSect3(""));
			fieldd.setText(msin.VoteSelectionSect4(""));
			}
			catch(Exception ex)
			{
				JOptionPane.showMessageDialog(null,"Internal IIOP Error....\nContact to the Administrator..","Error",JOptionPane.ERROR_MESSAGE);
			}
			
		}
}
